namespace Example.Models
{
    using System.Xml;
    using System.Xml.XPath;
    using SimpleWebServices;
    using SimpleWebServices.Globalization;
    using SimpleWebServices.Web;
    using Xunit;

    public sealed class DistanceFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Distance>()
                .DerivesFrom<Resource>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("distance")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Distance obj = (
                "<distance>" +
                    "<display>" +
                        "<translation xml:lang='en'>" +
                            "<string>xyz</string>" +
                        "</translation>" +
                    "</display>" +
                "</distance>").Deserialize<Distance>();

            Assert.Equal<string>("xyz", obj.Display["en"]);
        }

        [Fact]
        public void serialize()
        {
            Distance obj = new Distance
            {
                Display =
                {
                    { "en", "xyz" }
                }
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();
            XmlNamespaceManager namespaces = new XmlNamespaceManager(navigator.NameTable);
            namespaces.AddNamespace("xml", "http://www.w3.org/XML/1998/namespace");

            Assert.True((bool)navigator.Evaluate("1=count(/distance/display/translation[@xml:lang='en']/string[text()='xyz'])", namespaces));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Distance());
        }

        [Fact]
        public void prop_Display()
        {
            Assert.True(new PropertyExpectations(typeof(Distance).GetProperty("Display"))
                .TypeIs<TranslationCollection<string>>()
                .DefaultValueIsNotNull()
                .Result);
        }
    }
}